home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Environments / MacCjr / MacC Jr / ScrapDemo Folder / scrapDemo.c
Encoding:
C/C++ Source or Header  |  1987-01-05  |  1.5 KB  |  78 lines  |  [TEXT/EDIT]

  1. // scrapDemo.c
  2. // © Copyright 1987 Consulair Corp, All Rights Reserved
  3. // An example of how to read information from the
  4. // scrap or "ClipBoard".  It opens the scrap, reads its contents, 
  5. // writes them out to a file and to the tty screen, waits for a 
  6. // character, and exits.
  7.  
  8. #include <stdio.h>
  9. #include <memory.h>
  10.  
  11. extern char *_SF_Name;
  12.  
  13. main()
  14.   {
  15.   FILE *file;
  16.   char **scrapText, *scrapPtr;
  17.   int i;
  18.   long length, offset;
  19.   
  20.   scrapText = NewHandle(0);
  21.   if ((length = GetScrap(scrapText, 'TEXT', &offset)) >= 0)
  22.     {
  23.     HLock(scrapText);
  24.     scrapPtr = *scrapText;
  25.     // Write to TTY
  26.       printf("Got Scrap, length = %d, offset = %d\rContents: \r", length, offset);
  27.       for (i = 0; i < length; i++) printChar(scrapPtr[i]);
  28.     getchar();
  29.     
  30.     // And write to file
  31.       if (file = fopen(".SFout", "w"))
  32.         {
  33.     for (i = 0; i < length; i++) fputc(scrapPtr[i], file);
  34.     fclose(file);
  35.     makeEditFile(_SF_Name);
  36.     }
  37.     
  38.     HUnlock(scrapText);
  39.     DisposHandle(scrapText);
  40.     }
  41.   else
  42.     {
  43.     if (length == -102) printf("\rNo Data of type TEXT in scrap");
  44.     else printf("Error in reading scrap = %d", length);
  45.     getchar();
  46.     }
  47.   }
  48.   
  49.     
  50. printChar(c)
  51.   unsigned char c;
  52.   {
  53.   if (c < ' ')
  54.     {
  55.     switch(c)
  56.       {
  57.       case '\n':
  58.           putchar('\n');
  59.       break;
  60.       case '\t':
  61.         putchar(' ');
  62.     break;
  63.       default:
  64.     putchar('^');
  65.     putchar(c+'@');
  66.       }
  67.     }
  68.   else
  69.     if (c > 127)
  70.       {
  71.       putchar('|');
  72.       printChar(c-128);
  73.       }
  74.     else putchar(c);
  75.   }
  76.     
  77.  
  78.